package xin.petstore.framework.swagger;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SwaggerController {
    @RequestMapping(value = {"/restapi"}, method = {org.springframework.web.bind.annotation.RequestMethod.GET})
    public void api(HttpServletRequest request, HttpServletResponse response) {
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
        try {
            response.sendRedirect(path + "/api/index.html?url=" + basePath + "/api-docs");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
